package Servlet;
/*
@ClassName:     ServletAdd
@Author:        YangXu
@Need:          
@Date:          2022/4/27
@Time:          2022-04-27 21:53
*/

//


import entity.User;
import service.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/add")
public class ServletAdd extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset-utf-8");
        resp.setHeader("content-type","text/html;charset=utf-8");
        String account = req.getParameter("account");
        String name = req.getParameter("username");
        String pwd = req.getParameter("cfmPassword");
        String job = req.getParameter("jobb");
        String deptId = req.getParameter("deptId");
        UserServiceImp userServiceImp = new UserServiceImp();
        List<User> did = userServiceImp.getDeptId();
        if (account!=null){

        req.setAttribute("attrUserName",deptId);
        List<User> AddList = userServiceImp.add(account, name, pwd, job, deptId);
            req.getRequestDispatcher("/userList.jsp").forward(req,resp);
        }
        req.setAttribute("attrDeptList",did);
        req.getRequestDispatcher("/userAdd.jsp").forward(req,resp);

/*        if (AddList.size()!=0){
//            resp.getWriter().write("添加成功");
            resp.sendRedirect("");
            System.out.println("添加成功");
        }else {
            resp.getWriter().write("添加失败");
            System.out.println("添加失败");
        }*/
    }
}
/*

 */